﻿using CollegeSim.CourseScheduler.Presentation.Facade;
using System;
using System.Windows.Forms;

namespace CollegeSim.CourseScheduler.Presentation
{
    // Author: Ryan Redburn
    // Project: Course Scheduler
    // Date: 3/2/2014

    public partial class FormCourseSelect : Form
    {
        #region [ Fields ]

        private readonly SchedulerFacade _facade;

        #endregion

        #region [ Properties ]

        // Saved index value used to determine course selected by the user
        public int SelectionIndex;

        #endregion

        #region [ Constructors ]

        // Initialize facade on instantiation
        public FormCourseSelect(SchedulerFacade facade)
        {
            InitializeComponent();
            _facade = facade;
        }

        #endregion

        #region [ Events ]

        // Populate course list on load
        private void FormCourseSelect_Load(object sender, EventArgs e)
        {
            // Get course list form the facade
            cmbCourseSelect.DataSource = _facade.GetCourseList();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            // Inform the user if no course is selected
            if (cmbCourseSelect.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a course.", "Invalid Selection");
                return;
            }

            // Save selected index value for retrieval
            SelectionIndex = cmbCourseSelect.SelectedIndex;
            DialogResult = DialogResult.OK;
            Close();
        }

        // Close the form
        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        #endregion
    }
}
